import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:ushare/ushare.dart';

class UmengConfig {
  // static String appKey = "5f97bc961c520d307399d07d";
  // static String appSecret =
  //     "PCR+lMkDTcQ808Pmg/RiHRA8eHkPXh+yj19HCFp3909pc/REeFa2REz9UYxkGJstrN5YOARzjJU/c3XNwe2dZw0TKEswL37GAdGEMQ3zUJJnLZTRh+DX5w2lw9ycaP7dVsVgou+FTYWYOkn53ntyRigKTKlL4C8pBBXYDllAl5wl/5tBUo2xMrKkq6wRfXX74qJiw0xw5Ebd4fXx/Ri6pNFYS7P3RTx7xl3be+rlYsuGp8vM8IO1thRMwW4tLZD028HAcJ+nP2bApanzWosYO8O7pZcbemrw9VqKM2/URzAB29yEARBvSTRxuxuGwu/r";
  static String appKey = "5f506281a4aebb6a2feadb05";
  static String appSecret =
      "qZt4oEAuTfUDmjW82bcvS2VGYL6NLkTFvnfqY5uX862K8hi0xVf5PMH5K5k71qXwjfsRJwLPoinmaPvtcVO51lCi0exM9cuOuPA9NvgTJdhihOQo7xuSpim4WZjul07j8GcViq9Gi4V3QYCEO59XFav8qR75DsLRoEFVD0Q83cDD6UN8GMd7LDXI71h2pl7+/9giExVGqgimhrlzO7p9JuM8ZwSxrCTVMAf9jmBXwpx14pihFbtZkJJQzauP1HDXEXTlkfuY9c9j3P6KB4q2Kkfwdh0TmaXx";
  static String wxAppid = 'wx4b45c03fac7c6888';
  static String wxSecret = '36234e2002674c84fd5bd45548299d31';
  static String qqAppid = '101903813';
  static String weiboAppid = '628381199';
}

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    init();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: Wrap(
            children: [
              buildShare(text: '分享qq', platform: 0),
              buildShare(text: '分享qq空间', platform: 1),
              buildShare(text: '分享微信', platform: 2),
              buildShare(text: '分享微信朋友圈', platform: 3),
              buildShare(text: '分享微博', platform: 4),
              buildShare(text: '复制链接')
            ],
          )),
    );
  }

  Widget buildShare(
      {String text,
      String url = 'http://wwww.baidu.com',
      String imageUrl =
          'https://cms.samanlehua.com/cms/chendan/3f91d9f0-65f8-11eb-9d7a-c708be9712f3.png-noresize.webp',
      int platform = 4}) {
    return OutlineButton(
      child: Text(text),
      onPressed: () {
        Ushare.doShare(
            title: text,
            desc: text + 'desc',
            url: url,
            imageUrl: imageUrl,
            platform: platform);
      },
    );
  }

  Future<void> init() async {
    try {
      Ushare.init(
          appKey: UmengConfig.appKey,
          appSecret: UmengConfig.appSecret,
          wxAppid: UmengConfig.wxAppid,
          wxSecret: UmengConfig.wxSecret,
          qqAppid: UmengConfig.qqAppid,
          weiboAppid: UmengConfig.weiboAppid);
    } on PlatformException {
      // data = 'Failed to get platform version.';
    }
  }
}
